package ro.pub.cs.stadium.platform.general;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class InputDialog extends OkCancelDialog {
	
	private final Text textField;
	private final Label label;
	
	private String question = "";
	private String answer = "";
	
	public InputDialog(Shell mainWnd) {
		super(mainWnd, false);
		
		getWndShell().setText("Input Requested");
		
		
		textField = new Text(getWndShell(), SWT.SINGLE | SWT.BORDER);
		textField.setText("");
		
		label = new Label(getWndShell(), SWT.NONE);
		label.setText("Input:");
		

		
		FormData textData = new FormData();
		textData.left = new FormAttachment(0);
		textData.right = new FormAttachment(100);
		textData.bottom = new FormAttachment(getOkButton(), -10);
		textData.width = 300;
		textField.setLayoutData(textData);
		
		FormData labelData = new FormData();
		labelData.left = new FormAttachment(0);
		labelData.right = new FormAttachment(100);
		labelData.bottom = new FormAttachment(textField, -10);
		label.setLayoutData(labelData);
		
		getWndShell().pack();
	}
	
	public String getQuestion() {
		return question;
	}
	
	public void setQuestion(String question) {
		this.question = question; 
	}
	
	public String getAnswer() {
		return answer;
	}
	
	public void setAnswer(String answer) {
		this.answer = answer;
	}
	
	@Override
	public int showModal() {
		
		label.setText(question);
		
		return super.showModal();
	}

	/* (non-Javadoc)
	 * @see ro.pub.cs.stadium.platform.general.OkCancelDialog#doCancelAction()
	 */
	@Override
	protected void doCancelAction() {
		modalResult = -1;
		getWndShell().close();
		
	}

	/* (non-Javadoc)
	 * @see ro.pub.cs.stadium.platform.general.OkCancelDialog#doOkAction()
	 */
	@Override
	protected void doOkAction() {
		modalResult = 0;
		
		answer = textField.getText();
		
		getWndShell().close();
		
	}
	
	
}
